﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CommonClasses
{
    public class Deck
    {
        Random random_num = new Random();
        private List<Card> cards = new List<Card>();
        public List<Card> Cards 
        {
            get { return cards; }
            set { cards = value; } 
        }
        
        protected string[] suits = { "c", "d", "h", "s" };
        protected string[] rank = { "2", "3", "4", "5", "6", "7", "8", "9", "10", "j", "q", "k", "a" };
                
        public virtual void initialize_cards()
        {
            cards.Clear();

            for (int i = 0; i < suits.Count(); i++)
            {
                for (int j = 0; j < rank.Count(); j++)
                {
                    string img_path = string.Format(@"C:\Temp\CardImages\{0}{1}.png", rank[j], suits[i]);
                    string fd_img_path = @"C:\Temp\CardImages\facedown.png";

                    int num_value;

                    num_value = j + 2;                    

                    Card card = new Card(suits[i], rank[j], num_value, true, img_path, fd_img_path);
                    Cards.Add(card);
                }
            }
        }

        public Card GetCard()
        {
            Card selected_card;

            // Generate a random number between 0 and number of card available.
            int r_num = random_num.Next(0, Cards.Count());
            selected_card = Cards[r_num];

            // Remove the selected card from the list of available cards.
            Cards.RemoveAt(r_num);
                        
            return selected_card;
        }
    }    
}